<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<link href="/icon/sys_icon.css" type="text/css" rel="stylesheet"/>
<title>菜单管理</title>
<script>
	$(function(){
		p.isTreeGrid = true;
		p.dataGrid = $(p.dataGrid).treegrid($.extend({},p.dataGridParam,{
			url: "/console/com.fs.base.pojo.Menu/list" ,
			sortName:"menuOrder",
			sortOrder:"asc",
			columns: [[
		         {"field":"menuName","width":180,"title":"菜单名称" },
		         {"field":"menuUrl","width":180,"title":"菜单地址" },
		         {"field":"iconCls","width":170,"title":"菜单图标" },
		         {"field":"menuOrder","width":100,"title":"菜单排序" },
		         {"field":"menuMotion","minwidth":300,"title":"动作配置列表" ,formatter:function(value,row,index){
		        	 /*拉去动作列表*/
		        	 $.ajaxSettings.async = false;
		        	 var motions = [];
		        	 var param = { menuId: row.id, menuId_searchType: "eq",sort:"motionOrder" };
		        	 $.getJSON("/console/com.fs.base.pojo.MenuMotion/list", param ,function(data){
		        		 $.each(data.rows,function(idx,m){
		        			 motions.push(m.motionCode +  m.motionName);
		                 });
		        	 });
		        	 $.ajaxSettings.async = true;
		        	 return motions.join(" ");
		         }}
			]],
			idField: "treeId", 
			treeField: "menuName",
			queryParams:{isTreeGrid:"true", treeId:"id", treePid:"parentId" }
		}));
		
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var id = $(this).attr("motion_code");
			switch(id){
				case "01":
					var rows = p.dataGrid.datagrid('getSelections'), len = rows.length;
					var data = {parentId : "" , pmenuName : "无" }; 
					if(len>0){
						data = { parentId: rows[0].id || "" , pmenuName: rows[0].menuName || "无"};
					}
					p.gridAdd({ title : "菜单新增", width : 500, height : 320,data: data });
					break;
				case "02":
					p.gridModify({title : "菜单编辑" ,width : 500, height : 270 });
					break;
				case "03":
					p.gridDelete({ url :  "/console/com.fs.base.pojo.Menu/delete" });
					break;
				case "05":
					p.gridQuery();
					break;
				case "09":
					var rows = p.dataGrid.datagrid('getSelections'), len = rows.length || 0 ;
					if(len<=0){
						p.tip({ msg : '请选择一条记录进行配置！' }); return;
					} 
					var row = rows[0];
					if(row.children && row.children.length>0){
						p.tip({msg: '父菜单无需配置按钮动作！'}); return;
					}
					var _p = {
						title : "菜单动作配置", width : 500, height : 400, href : p.gridConfigUrl || '',data : row ,
						buttons : [ p.buttons.submit, p.buttons.close ]
					};
					p.dialog = $("<div/>").dialog("openWin", _p);
					break;
				case "11":
					p.gridOpt({ href: '/console/menu/move',width : 400, height : 500, title : "菜单移动",buttons : [ p.buttons.submit, p.buttons.close ]});
					break;
				default: 
					p.tip({msg: $(this).text() +'未添加响应事件！'}); break;
			}
		});
	});
</script>
</head>
<body class="easyui-layout">
	<!-- 但行高度33px，多行时 33乘以行数  -->
	<div id="querybar" data-options="region:'north',split:false,border:false" style="height:33px;">
		<div class="easyui-panel" data-options="fit:true,border:false"  >
			<form id="queryForm">
				<input type="hidden" name="className" value="com.fs.base.pojo.Menu" />
				<div style="margin-top:5px;margin-left:10px;float:left;">
					<input class="easyui-textbox" name="menuName" style="width:240px;" data-options="label:'菜单名称:',required:false" />
					<input type="hidden" name="menuName_searchType" value="like" />
				</div>
				<div style="margin-top:5px;margin-left:10px;float:left;">
					<input class="easyui-textbox" name="menuUrl" style="width:240px;" data-options="label:'菜单地址:',required:false" />
					<input type="hidden" name="menuUrl_searchType" value="like" />
				</div>
			</form>		
		</div>
	</div>  

	<!-- 工具栏 -->
	<div id="toolbar" class="easyui-panel" style="padding:3px;">
		<!-- 工具栏按钮
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="01">新增</a>
      	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="02">编辑</a>
     	<a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" id="03">删除</a>
      	<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="05">查询</a>
     	<a href="#" class="easyui-linkbutton" iconCls="icon-config" plain="true" motion_code="25">动作设置</a>
		  -->
	</div>
	
	<!-- 表格 --> 
	<div region="center" border="false">
		<table id="dataGrid"></table>
	</div>
</body>
</html>